package com.aweqy.porcelain.controller;

import com.aweqy.porcelain.common.BaseResponse;
import com.aweqy.porcelain.common.ResultUtils;
import com.aweqy.porcelain.entity.Literature;
import com.aweqy.porcelain.service.LiteratureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文献信息控制器
 */
@Api(tags = "文献信息管理")
@RestController
@RequestMapping("/literature")
@CrossOrigin(origins = "*")
public class LiteratureController {
    
    @Autowired
    private LiteratureService literatureService;
    
    @ApiOperation("根据朝代和地区获取文献列表")
    @GetMapping("/dynasty/{dynastyId}/region/{regionId}")
    public BaseResponse<List<Literature>> getLiteraturesByDynastyAndRegion(
            @ApiParam("朝代ID") @PathVariable Integer dynastyId,
            @ApiParam("地区ID") @PathVariable Integer regionId) {
        List<Literature> literatures = literatureService.getLiteraturesByDynastyAndRegion(dynastyId, regionId);
        return ResultUtils.success(literatures);
    }
    
    @ApiOperation("根据朝代获取文献列表")
    @GetMapping("/dynasty/{dynastyId}")
    public BaseResponse<List<Literature>> getLiteraturesByDynasty(
            @ApiParam("朝代ID") @PathVariable Integer dynastyId) {
        List<Literature> literatures = literatureService.getLiteraturesByDynasty(dynastyId);
        return ResultUtils.success(literatures);
    }
    
    @ApiOperation("根据地区获取文献列表")
    @GetMapping("/region/{regionId}")
    public BaseResponse<List<Literature>> getLiteraturesByRegion(
            @ApiParam("地区ID") @PathVariable Integer regionId) {
        List<Literature> literatures = literatureService.getLiteraturesByRegion(regionId);
        return ResultUtils.success(literatures);
    }
    
    @ApiOperation("根据文献ID获取文献详情")
    @GetMapping("/{literatureId}")
    public BaseResponse<?> getLiteratureById(
            @ApiParam("文献ID") @PathVariable Integer literatureId) {
        Literature literature = literatureService.getLiteratureById(literatureId);
        if (literature == null) {
            return ResultUtils.error(404, "文献不存在");
        }
        return ResultUtils.success(literature);
    }
} 